/**
 ******************************************************************************
 * @file    swTimer.h
 * @author .ISS_AUTO (hudandan@issauto.com)
 * @
 * @version 2022-06-21   Base version.
 *          2023-07-11   1. 新增计时器复位函数 void swt_RstTickCount(void).
 *          2024-01-22   1. 新增计时器延时函数 void swt_Delay(swt_TimeType timeout).
 *          2024-10-30   1. 新增计时器差值函数 swt_TimeType swt_GetDeltaCount(swt_TimeType start).
 *                       2. 新增计时器比较函数 uint8_t swt_IsTimeout(swt_TimeType start, swt_TimeType time).
 *          2024-11-08   1. 适配 MCU: N32G45X.
 *
 * @brief   This file for swtimer module.
 *
 * @copyright Copyright (c) 2023 ISSAUTO TECH Co., Ltd. All rights reserved.
 *
 ******************************************************************************
 */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef _USER_SWTIMER_H_
#define _USER_SWTIMER_H_

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include <stdint.h>

/* Exported types ------------------------------------------------------------*/
typedef uint32_t swt_TimeType; //!< Data type for time representation  (32 bit -> wrap arount every ~49 days)

typedef struct _swt_CntDown_t {
    swt_TimeType StartTime;
    swt_TimeType CntDownTime;
} swt_CntDown_t;

/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
#define SWT_TICK_MAX    ((uint32_t)0xFFFFFFFF)  //!< Has to correspond to maximum value representable as swt_TimeType 

/* Exported variables --------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void swt_TimerCallback(void);

//! Reset current tick count.
void swt_RstTickCount(void);

//! Returns current tick count
swt_TimeType swt_GetTickCount(void);

//! Returns delta tick count
swt_TimeType swt_GetDeltaCount(swt_TimeType start);

//! Returns whether delta tick count is timeout
uint8_t swt_IsTimeout(swt_TimeType start, swt_TimeType time);

//! delay count
void swt_Delay(swt_TimeType timeout);

#ifdef __cplusplus
}
#endif

#endif /* _USER_SWTIMER_H_ */

/* END OF FILE ---------------------------------------------------------------*/
